<template>
  <section>
    <header class="app_header">
      <span class="header_title" @click="changeStyle(0)"><router-link to="/">Shopping Cart</router-link></span>
      <span  :class="{active:isSelected=='1'}" @click="changeStyle(1)"><router-link to="/">iphone 6s</router-link></span>
      <span  :class="{active:isSelected=='2'}" @click="changeStyle(2)"><router-link to="cart">购物车 <span class="shopping_number" v-if="cart.length>0">{{cart.length}}</span></router-link>
      </span>
    </header>
    <div>
      <router-view></router-view>
    </div>
  </section>
</template>

<script>
import { mapState } from 'vuex'
  export default {
    name: 'App',
    data() {
      return {
        isSelected: '0',
        cartNumber:0
      }
    },
    computed:mapState(['cart']),
    methods: {
      changeStyle(index) {
        this.isSelected = index;
      }
    }
  }
</script>

<style lang="less" scoped>
  header.app_header {
    display: flex;
    padding-left: 20px;
    height: 60px;
    line-height: 60px;
    background-color: #f8f8f8;
    border-top: 1px solid #ccc;
    border-bottom: 1px solid #ccc;
    .header_title {
      font-size: 22px;
      font-weight: 300;
      &~span {
        margin-left: 30px;
        padding: 0 10px;
        a {
          display: inline-block;
          width: 100%;
          height: 100%;
        }
      }
    }
  }
  .shopping_number {
    color: #fff;
    background-color: #d9534f;
    min-width: 18px;
    padding: 1px 7px;
    font-size: 12px; // display: inline-block;
    height: 18px;
    text-align: center;
    vertical-align: middle;
    font-weight: 700;
    border-radius: 10px;
  }
  .active {
    background-color: #eeeeee
  }
</style>

